package com.miao.util.converter;

import org.apache.commons.lang.StringUtils;
import org.springframework.core.convert.converter.Converter;

import java.util.Date;

/**
 * @author Created by Miaosk
 * @date Created on 2015/5/19.
 */
public class DateConverter implements Converter<String, Date> {
    @Override
    public Date convert(String source) {
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        dateFormat.setLenient(false);
//        try {
//            return dateFormat.parse(source);
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        return null;

        if (StringUtils.isNotBlank(source)) {
            Date date = new Date(Long.parseLong(source));
            return date;
        }
        return null;

    }
}
